from fastapi import APIRouter

from app.core.responses import Response
from app.schemas.ad import AdSM, AdSlotSM
from app.services.ad import AdServices

router = APIRouter()


@router.get('/ad')
def index():
    data = AdServices.slot_index()
    return Response.success({'list': data})


@router.post('/ad')
def ad(form: AdSM):
    if AdServices.store(form):
        return Response.success('操作成功！')


@router.delete('/ad/{id}')
def ad(ad_id: int):
    if AdServices.destroy(ad_id):
        return Response.success('操作成功！')


@router.post('/ad/{id}')
def ad(ad_id: int, form: AdSM):
    if AdServices.update(ad_id, form):
        return Response.success('操作成功！')


@router.post('/ad_slot')
def ad_slot(form: AdSlotSM):
    if AdServices.slot_store(form):
        return Response.success('操作成功！')


@router.delete('/ad_slot/{id}')
def ad_slot(slot_id: int):
    if AdServices.slot_delete(slot_id):
        return Response.success('操作成功！')


@router.post('/ad_slot/{id}')
def ad_slot(slot_id: int, form: AdSlotSM):
    if AdServices.slot_update(slot_id, form):
        return Response.success('操作成功！')
